package org.example.yunshu.demos.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class MessageWebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private MessageWebSocket messageWebSocket ;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
      registry.addHandler(messageWebSocket , "/socket")
              .addInterceptors(new HttpSessionHandshakeInterceptor());
      // 添加拦截器,让WebSocketSession 建立时 ,复制httpsession的Attribute
    }
}
